package com.cn.zpark.controller;

import com.cn.zpark.beans.User;
import com.cn.zpark.service.IFindUserService;
import com.cn.zpark.service.impl.FindUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @PackageName: com.cn.zpark.controller
 * @ClassName: UserServletController
 * @Description:控制层
 * @author: RZS
 * @date: 2022/4/27  16:08
 */
@WebServlet("/find_user.do")
public class FindUserServletController extends HttpServlet {

    // 创建service业务层对象
    private IFindUserService userService = new FindUserServiceImpl();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 由于不要请求参数，所以直接调用service业务层查询数据
        List<User> users = userService.selectUser();
        // 将查询结果数据绑定到请求域对象中
        request.setAttribute("users", users);
        // 转发给JSP做展示
        request.getRequestDispatcher("jsp/demo01.jsp").forward(request, response);
    }
}
